package com.chsi.onjava8.lambda;

import java.util.function.Function;

/**
 * @Auther shikf
 */
public class CurryingAndPartials {
    // 未柯里化:
    static String uncurried(String a, String b) {
        return a + b;
    }

    public static void main(String[] args) {
        // 柯里化的函数:
        Function<String, Function<String, String>> sum =
                a -> b -> a + b; // [1]

        System.out.println(uncurried("First ", "Sencond"));

        Function<String, String>
                hi = sum.apply("First "); // [2]
        System.out.println(hi.apply("Sencond"));

        // 部分应用:
        Function<String, String> sumHi =
                sum.apply("First ");
        System.out.println(sumHi.apply("XXXX"));
        System.out.println(sumHi.apply("YYYY"));

        Function<String,Function<String, Function<String, String>>> sum_self =
                a -> b -> c -> a + b + c; // [1]
        String apply = sum_self.apply("first ").apply("second ").apply("third");
        System.out.println(apply);
    }
}
